package com.hhc.netty;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class NettyStartListener implements ServletContextListener {
    private NettyServer nettyServer;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        new Thread(){
            @Override
            public  void run(){
                try {
                    nettyServer = new NettyServer(8888);
                    nettyServer.run();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        try {
            nettyServer.stop();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
